package com.sauron.starter.vo;

import com.alibaba.druid.util.StringUtils;
import com.sauron.starter.constants.MsgCode;

public class ResultVO {

    private int code;
    private String msg;
    private Object data;
    private String detailMsg;

    private ResultVO(MsgCode msgCode) {
        if (msgCode == null) return;
        this.code = msgCode.getCode();
        this.msg = msgCode.getMsg();
    }

    private ResultVO(MsgCode msgCode, String detailMsg) {

        if (msgCode == null) return;
        this.code = msgCode.getCode();
        this.msg = msgCode.getMsg();
        this.detailMsg = detailMsg;
    }

    private ResultVO(Object data){
        this.code = MsgCode.SUCCESS.getCode();
        this.msg = MsgCode.SUCCESS.getMsg();
        this.data = data;
    }

    public static ResultVO success(Object data){
        return new ResultVO(data);
    }

    public static ResultVO success(){
        return success("");
    }

    public static ResultVO error(MsgCode msgCode){
        return new ResultVO(msgCode);
    }

    public static ResultVO error(MsgCode msgCode,String detailMsg){
        if (StringUtils.isEmpty(detailMsg)){
            return new ResultVO(msgCode);
        }else {
            return new ResultVO(msgCode,detailMsg);
        }
    }

}
